/*
 * LayerView.java
 *
 * Created on July 11, 2008, 8:06 PM
 */

package anivis.ui.timeline;

import anivis.base.DataAvailableNotification;
import anivis.base.Notification;
import anivis.base.RestrictionNotification;
import anivis.db.QueryLayer.Restriction;
import anivis.db.QueryLayer.RestrictionType;
import anivis.layers.ObservationLayer;
import anivis.ui.Controller;
import java.util.AbstractSet;
import java.util.HashSet;
import java.util.Observable;
import java.util.Set;
import prefuse.Display;

/**
 *
 * @author  urp
 */
public class LayerView extends Display implements java.util.Observer
{
    private anivis.ui.Controller  controller   = null;
    private ObservationLayer      layer;
    private boolean               waitsForData = true;
    /** Creates new form LayerView */
    public LayerView() 
    {
        initComponents();
        anivis.AniVisApp.getApplication().getController().addObserver(this);
        layer = new ObservationLayer("Avian Networks",true,true);
        layer.setRestrictionTypes(createRestrictionTypes());
    }
    
    static protected Set<RestrictionType> createRestrictionTypes()
    {
      Set<RestrictionType> r = new HashSet<RestrictionType>();
      r.add(RestrictionType.TimeSpan);
      return r;
    }
    
    //protected addVisualization()
    //{
      
    
    
    //}
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    setName("Form"); // NOI18N

    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(0, 598, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
      .add(0, 85, Short.MAX_VALUE)
    );
  }// </editor-fold>//GEN-END:initComponents


  // Variables declaration - do not modify//GEN-BEGIN:variables
  // End of variables declaration//GEN-END:variables

  public void update(Observable sender, Object message) 
  {
    Notification notification = (Notification) message;
    
    if(notification.isRestrictionNotification())
    {
       RestrictionNotification n = (RestrictionNotification) notification;
       if( layer.getRestrictionTypes().contains( n.getRestriction().getType() ) )
       { waitsForData = true; }
    }
    else
      if(notification.isDataAvaialableNotification()) 
      { 
        DataAvailableNotification n = (DataAvailableNotification) notification;
        Set<RestrictionType> rT = n.getRestrictionTypes();
        if(waitsForData && rT.contains(layer.getRestrictionTypes()))
        {  /*get data*/
          anivis.ui.Controller c = (Controller) sender;
          
          layer.getData(c);
          waitsForData = false;
        }
      }  
      
  }

}
